package com.george.common.entity.dto;

import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * @title: PageResp.java
 * @description: 分页数据响应实体
 * @author: George
 * @date: 2023/6/28 9:14
 */
@Data
public class PageResp<T> {


    private Integer currentPage;
    private Integer currentRow;
    private List<T> dataList;
    private Boolean hasPreviousPage;
    private Boolean hasNextPage;
    private Integer totalPage;
    private Integer totalRows;

    public PageResp(List<T> dataList, Integer pageNo, Integer pageSize, Integer totalRows) {
        this.currentPage = pageNo;
        this.currentRow = pageSize;
        this.totalRows = totalRows;
        this.dataList = dataList;

        this.totalPage = totalRows / pageSize + (totalRows % pageSize > 0 ? 1 : 0);
        this.hasNextPage = (pageNo < totalPage);
        this.hasPreviousPage = (pageNo > 1);
    }

    public PageResp() {
        this.currentPage = 1;
        this.currentRow = 0;
        this.totalRows = 0;
        this.dataList = Collections.emptyList();
        this.totalPage = 0;
        this.hasNextPage = false;
        this.hasPreviousPage = false;
    }


}